from appium.webdriver.common.touch_action import TouchAction
from appium import webdriver
import time
import random

# 设置终端参数项

desired_caps = {
    'platformName': 'Android',
    'platformVersion': '7.0',
    'deviceName': 'xxx',
    'appPackage': 'com.example.firstproject',
    'appActivity': 'com.example.mappoint.activity.LoginActivity',
    'noReset': True

}
# 发送指令给到appium server
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

# 点击取消更新按钮
# driver.find_element_by_id("com.example.firstproject:id/negtive").click()

# 点击登录按钮
driver.find_element_by_id("com.example.firstproject:id/tv_login").click()

# 点击地图图标进入地图Activity
driver.find_element_by_id("com.example.firstproject:id/mapimg").click()

# 长按点击地图打点  然后点确定  这里需要打很多点  所以做成循环
# 获取地图元素对象
for i in range(2000):
    el = driver.find_element_by_class_name('android.widget.ImageView')
    x = random.randint(1, 1919)
    y = random.randint(200, 1000)
    print(x)
    print(y)
    TouchAction(driver).long_press(el, x, y, duration=2000).release().perform()
    time.sleep(0.1)
    driver.find_element_by_id("com.example.firstproject:id/commit").click()
    time.sleep(0.1)
